﻿@using QDT.Common
@using QDT.Core.Domain
@using QDT.Core.Members
@using QDT.Web
@model QDT.Core.Members.User
@{
    ViewBag.Title = "绑定银行卡";
    var banks = ViewData["UserBank"] as ICollection<UserBank>;
    var bankId = ViewData["Banks"] as ICollection<Bank>;
}
@section Head
{
    <script type="text/javascript">
        $().ready(function () {
            $("#BankManager").css("background", "#e0524b");
            $("#BankManager i,#BankManager span").css("color", "white");
            $("#BankManager .san-jiaoxing").css("display", "block");
        });

        $().ready(function () {
            $('#BankId').change(function () {
                if ($('#BankId').val() == '9999') {
                    $('#OtherBank').removeClass('hide');
                } else {
                    $('#OtherBank').addClass('hide');
                }
            });
            $('#RegionLv2').change(function () {
                ajaxGetRegion($('#RegionLv2').val());
            });
            function ajaxGetRegion(pid) {
                $.ajax({
                    type: "post", //使用get方法访问后台
                    dataType: "json", //返回json格式的数据
                    url: "/Region/Region", //要访问的后台地址
                    data: "pid=" + pid,
                    success: setRegion
                });
            }
            function setRegion(result) {
                var total = result.total;
                if (total == 0) {
                    return false;
                }
                var rows = result.rows;
                var regionlevel = rows[0].RegionLevel;
                var region3 = document.getElementById('RegionLv3');
                var eText, eValue, i;
                if (regionlevel == 3) {
                    region3.options.length = 0;
                    region3.options.add(new Option("请选择", "0"));
                    for (i = 0; i < total; i++) {
                        eText = rows[i].Name;
                        eValue = rows[i].ID;
                        region3.options.add(new Option(eText, eValue));
                    }
                }
            }

            $('#submit_addbank').click(function () {
                addUserBank();
            });

            function addUserBank() {
                var bankCard = $('#BankCard').val();
                var bankId = $('[name="BankId"]').val();
                var otherBank = $('[name="OtherBank"]').val();
                var regionLv2 = $('[name="RegionLv2"]').val();
                var regionLv3 = $('[name="RegionLv3"]').val();
                var bankZone = $('#BankZone').val();

                if (bankZone == "快捷银行卡无需输入支行名称" || bankZone == "请输入正确的支行名称") {
                    bankZone = "";
                }

                var data = {};

                if (bankCard == "") {
                    alert("请填写银行卡号");
                    return;
                }

                if (bankId == 0) {
                    alert("请选择银行卡开户银行");
                    return;
                }
                if (regionLv3 == "") {
                    alert("请选择银行卡开户城市");
                    return;
                }

                data.BankCard = bankCard;
                data.BankId = bankId;
                data.OtherBank = otherBank;
                data.RegionLv2 = regionLv2;
                data.RegionLv3 = regionLv3;
                data.BankZone = bankZone;

                var url = '@Url.Action("PostBindBankCard")';

                $.ajax({
                    url: url,
                    data: data,
                    type: 'POST',
                    dataType: "json",
                    success: function (obj) {
                        alert(obj.Info);
                        if (obj.Status == true)
                            location.href = location.href;
                    }
                });
            }

        });

        function deletebank(id) {

            if (!confirm("确认删除银行卡")) {
                window.event.returnValue = false;
                return;
            }

            var url = '@Url.Action("DeleteBankCard")' + '?bankid=' + id;
            $.ajax({
                url: url,
                type: 'get',
                dataType: "json",
                success: function (obj) {
                    alert(obj.Info);
                    if (obj.Status == true) location.href = location.href;
                }
            });
        }

        function defaultbank(id) {
            var url = '@Url.Action("DefaultBankCard")' + '?bankid=' + id;
            $.ajax({
                url: url,
                type: 'get',
                dataType: "json",
                success: function (obj) {
                    alert(obj.Info);
                    if (obj.Status == true) location.href = location.href;
                }
            });
        }

        function showmyli() {
            $("#bank_ul").slideDown("fast");
        }

        $(function () {
            $("#bank_ul li").hover(function () {
                $(this).attr("style", "background:#cccccc");
            }, function () {
                $(this).removeAttr("style", "background:#cccccc");
            });
            $("#BankZone").focus(function () {
                var $sign = $("#BankZone").val();
                if ($sign == "快捷银行卡无需输入支行名称" || $sign == "请输入正确的支行名称") {
                    $("#BankZone").val("");
                    $("#BankZone").css("color", "black");
                }
            });
        });

        function addText(num) {
            var $mytext = $("#li_" + num).text();
            $("#bank_value").text(num);
            $("#BankId").val(num);
            $("#text_band").text($mytext);
            $("#bank_ul").slideUp("fast");

            var rec = $("#li_" + num).attr("data-rec");

            if (rec=="false") {
                $("#BankZone").val("请输入正确的支行名称");
                $("#BankZone").css("color", "#ababab");
            } else {
                $("#BankZone").val("快捷银行卡无需输入支行名称");
                $("#BankZone").css("color", "#ababab");
            }
        }
    </script>
}
<link href="/Content/Default/CSS/BindBankCard.css" rel="stylesheet" type="text/css" />
<div class="">
    @Html.Action("_UserBanner")
    <div class="ui-inner">
        <div class="ui-grid-row">
            @Html.Action("UserMenu", new { route = MenuRoute.CardsManage })
            <div class="ui-grid-20" style="width: 758px; font-size: 14px; margin: 0;">
                <div style="height: 40px; line-height: 40px; background-color: #d9edf6; padding-left: 30px;
                    margin-top: 10px; margin-left: 10px; width: 682px;">
                    <p>
                        为保证提现成功,请确认该银行卡开户姓名必须为：<span>@Model.RealName</span></p>
                </div>
                <div class=" ui-bank-list fn-clear" style="border-bottom: 1px solid #ccc;">
                    <div style="float: left; width: 365px; height: 560px;">
                        @foreach (var userbank in banks)
                        {
                            var bank = @Html.F().GetBank(userbank.BankId);
                            <div class="ui-inbox" style="border-radius: 3px; margin: 5px 10px;">
                                <div class="ui-inbox-head" style="border-radius: 3px;">
                                    <div>
                                        <span style="display: initial; float: left;">
                                            <img src="@(string.IsNullOrEmpty(bank.Logo) ? "" : bank.Logo)" />
                                            &nbsp;&nbsp;</span>
                                        <h3 class="ui-inbox-head-title">
                                            @Html.F().GetBankById(userbank.BankId)</h3>
                                    </div>
                                    @if (userbank.IsDefault)
                                    {
                                        <div class="ui-inbox-head-more" style="color: #27ae60;">
                                            <i class="iconfont">&#xf00b2;</i> <span style="background: #ffa304;color: white;border-radius: 2px;padding: 0 2px 0 2px;">已绑定</span> 
                                            <span class="ui-inbox-head-text">
                                                <a href="javascript:void(0);" onclick="deletebank(@userbank.ID);">删除</a> 
                                            </span>
                                        </div>
                                    }
                                    else
                                    {
                                        <div class="ui-inbox-head-more">
                                            <a style="color: #f39c12;" href="javascript:void(0);" onclick="defaultbank(@userbank.ID);">设为默认</a>
                                            <span class="ui-inbox-head-text">
                                                <a href="javascript:void(0);" onclick="deletebank(@userbank.ID);">删除</a>
                                            </span>
                                        </div>
                                    }
                                </div>
                                <div class="ui-inbox-container">
                                    <div class="ui-inbox-content" style="margin-left: 60px;">
                                        <ul style="margin-left: -5px; line-height: 28px; margin-top: -5px;">
                                            <li>卡号<span>@userbank.BankCard.ToConfuse(0, 6, 3)</span></li>
                                            <li>户名<span>@Model.RealName</span></li>
                                            <li style="margin-left: -30px;">开户网点<span>@userbank.BankZone</span></li>
                                        </ul>
                                    </div>
                                    @if (Html.F().GetBank(userbank.BankId).IsRec)
                                    {
                                        <img src="/Content/Default/Images/bank_kj.png" class="sale_image" />
                                    }
                                    else
                                    {
                                        <img src="/Content/Default/Images/bank_t1.png" class="sale_image" />
                                    }
                                </div>
                            </div>
                        }
                    </div>
                    <div class="ui-inbox" style="border-radius: 3px;">
                        <div class="ui-inbox-container">
                            <div class="ui-inbox-content" style="padding: 0 20px;">
                                <form class="ui-form ui-form-mini" method="post" action="@Url.Action("PostBindBankCard")" id="bind_bankcard_form">
                                <fieldset>
                                    <div class="ui-form-item">
                                        <label for="" class="ui-label">
                                            持卡人
                                        </label>
                                        <span class="" type="text" style="margin-top: 5px; display: inline-block; margin-left: 20px;
                                            font-size: 14px;">@(Model.IDCardPassed ? Model.RealName : "请先实名认证")</span>
                                    </div>
                                    <div class="ui-form-item">
                                        <label for="" class="ui-label">
                                            银行卡号
                                        </label>
                                        <input type="text" id="BankCard" name="BankCard" class="ui-input" style="width: 180px" />
                                    </div>
                                    <div class="ui-form-item">
                                        <label for="" class="ui-label">
                                            选择银行
                                        </label>
                                        <div style="position: relative; width: 200px;">
                                            <input type="hidden" id="BankId" name="BankId" class="hide" value="0"/>
                                            <div id="div_text_band" onclick="showmyli()">
                                                <span id="text_band" onclick="showmyli()">-- 请选择 --</span><span style="display: none;" id="bank_value"></span>
                                            </div>
                                            <span onclick="showmyli()" id="sanjiao"></span>
                                            <ul id="bank_ul">
                                                @foreach (var b in bankId.OrderByDescending(x => x.IsRec))
                                                {
                                                    <li id="@("li_" + b.ID)" onclick="addText(@b.ID)" class="@(b.IsRec ? "" : "no_user")" data-rec="@(b.IsRec ? "true" : "false")">@b.Name</li>
                                                }
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="ui-form-item" style="position: relative;">
                                        <label for="" class="ui-label">
                                            开户城市
                                        </label>
                                        @Html.DropDownList("RegionLv2", ViewData["RegionLv2"] as IEnumerable<SelectListItem>, new { @class = "ui-input", style = "width: 100px;" })
                                        <select id="RegionLv3" name="RegionLv3" class="ui-input" style="width: 100px;">
                                            <option value="0">市</option>
                                        </select>
                                        <span id="sanjiao1"></span><span id="sanjiao2"></span>
                                    </div>
                                    <div class="ui-form-item">
                                        <label for="" class="ui-label">
                                            支行名称
                                        </label>
                                        <input type="text" id="BankZone" name="BankZone" class="ui-input" style="width: 180px" />
                                    </div>
                                    <div class="ui-inbox-head-more">
                                        <input type="checkbox" id="set_default" checked="checked" /><span><label for="set_default"
                                            style="color: #e74c3c; font-size: 13px; margin-left: 10px;" href="javascript:void(0);"
                                            onclick="">设为默认</label></span></div>
                                    <div class="ui-form-item" style="padding-bottom: 0">
                                        @if (Model.IDCardPassed)
                                        {
                                            <a type="submit" href="javascript:void(0)" id="submit_addbank" class="ui-button ui-button-orange">
                                                添加</a>
                                        }
                                        else
                                        {
                                            <a type="submit" href="@Url.Action("BindIdCard")" class="ui-button ui-button-orange">
                                                实名认证</a>
                                        }
                                    </div>
                                </fieldset>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <div style="margin-left: 10px; margin-top: 20px;">
                    <span style="margin-bottom: 10px; font-size: 18px; display: inline-block;">温馨提示</span><br />
                    <div>
                        <span>请仔细核对账号信息，务必保证卡号无误，否则将导致提现失败！</span><br />
                        <span>请务必保证开户行网点准确无误，否则将导致提现失败！</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div style="margin-top: -9px;">@Html.Partial("_BindBottomImage")</div>
